/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.util;

import java.util.LinkedList;

/**
 *
 * @author rothens
 */
public class TextUtil {
    public static final String UC_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    public static final String LC_LETTERS = "abcdefghijklmnopqrstuvwxyz";
    public static final String UC_ACCENTS = "ÁÉÍÓÖŐÚÜŰ";
    public static final String LC_ACCENTS = "áéíóöőúüű";
    public static final String DIGITS = "0123456789";
    
    public static LinkedList<String> wrapText(String text, int maxlength){
        LinkedList<String> ret = new LinkedList<String>();
        String[] split = text.split(" ");
        String line = "";
        for(String s : split){
            if (line.length() + 1 + s.length() > maxlength){
                if(line.length() > 0){
                    ret.add(line);
                    line = "";
                }
                
                while(s.length() > maxlength){
                    ret.add(s.substring(0, maxlength-1) + "-");
                    s = s.substring(maxlength-1);
                }
            }
            
            line += ((line.isEmpty())?"":" ") + s;           
        }
        ret.add(line);
        
        return ret;
    }
    
    public static void main(String... args){
        LinkedList<String> wrapped = wrapText("The quickestlol brown fox has jumped over the lazy dog", 9);
        for(String s : wrapped){
            System.out.println(s);
        }
    }

    
}
